<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: xajax.translations.php 11 2013-09-21 11:43:11Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 11 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 11:43:11 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

$xajax->registerFunction('getDefines');
$xajax->registerFunction('saveDefines');
$xajax->registerFunction('newDefinition');
$xajax->registerFunction('saveNewDefines');

function getDefines($value, $lng_id) {
	global $db;

	$ajax = new xajaxResponse();

	$r = $db->db_query("SELECT
								lang_define,
								lang_desc
							FROM
								".DB_PREFIX."language_".$lng_id."
							WHERE
								lang_define LIKE '%".$value."%'
							OR
								lang_desc LIKE '%".$value."%'");
	if($r->_numOfRows > 0) {
		$c = '<table width="100%" cellpadding="8">';
		while(!$r->EOF) { $cnt++;
			$c .= '	<tr'.($cnt%2 ? ' class="dunkel"' : '').'>';
			$c .= '		<td valign="top" width="1"><input type="hidden" id="define_'.$cnt.'" type="text" value="'.$r->fields['lang_define'].'" /><b>'.$r->fields['lang_define'].'</b></td>';
			$c .= '		<td><textarea id="text_'.$cnt.'" class="phrase_text">'.$r->fields['lang_desc'].'</textarea></td>';
			$c .= '		<td width="1" align="right" valign="top">
							<button class="button" onclick="save('.$cnt.');">
								Speichern
							</button>
						</td>';
			$c .= '	</tr>';
			$r->MoveNext();
		}
		$c .= '</table>';

	} else {
		$c = '';
	}

	$ajax->assign('translation_results', 'innerHTML', $c);

	return $ajax;
}

function saveNewDefines($def, $txt, $lng, $num) {
	global $db;

	$ajax = new xajaxResponse();

	$check = $db->db_query("SELECT
								lang_define
							FROM
								".DB_PREFIX."language_".$lng."
							WHERE
								lang_define = '".$def."' ");
	if($check->_numOfRows < 1) {
		$db->db_query("INSERT INTO ".DB_PREFIX."language_".$lng." (lang_define, lang_desc) VALUES ('".$def."', '".$txt."')");
		$j .= '$.gritter.add({'."\n";
		$j .= '		title: \'Erfolgreich gespeichert\','."\n";
		$j .= '		text: \'Die Definition "'.$def.'" wurde gespeichert.\','."\n";
		$j .= '		image: \''.DIR_WS_ICONS.'dialog-success.png\','."\n";
		$j .= '		sticky: false,'."\n";
		$j .= '		time: 3500'."\n";
		$j .= '});';
		$ajax->script('jQuery("#row_'.$num.'").fadeOut(900,function(){jQuery(this).remove();});');

	} else {
		$j .= '$.gritter.add({'."\n";
		$j .= '		title: \'Fehler!\','."\n";
		$j .= '		text: \'Diese Definition existiert bereits in der Datenbank.\','."\n";
		$j .= '		image: \''.DIR_WS_ICONS.'dialog-error.png\','."\n";
		$j .= '		sticky: false,'."\n";
		$j .= '		time: 4000'."\n";
		$j .= '});';
	}

	$ajax->script($j);

	return $ajax;
}

function saveDefines($def, $txt, $lng, $num) {
	global $db;

	$ajax = new xajaxResponse();

	$db->db_query("UPDATE ".DB_PREFIX."language_".$lng." SET lang_desc = '".$txt."' WHERE lang_define = '".$def."' ");

	$j .= '$.gritter.add({'."\n";
	$j .= '		title: \'Erfolgreich gespeichert\','."\n";
	$j .= '		text: \'Die Definition "'.$def.'" wurde gespeichert.\','."\n";
	$j .= '		image: \''.DIR_WS_ICONS.'dialog-success.png\','."\n";
	$j .= '		sticky: false,'."\n";
	$j .= '		time: 3500'."\n";
	$j .= '});';

	$ajax->script($j);

	return $ajax;
}

function newDefinition() {
	$ajax = new xajaxResponse();

	$l = get_languages();
	$c 	= '<br /><table width="100%" cellpadding="6">';
	$c .= '		<tr>
					<td>&nbsp;</td>
					<td><b>Konstante</b></td>
					<td><b>der Text dazu</b></td>
				</tr>';
	for ($i = 0, $n = sizeof($l); $i < $n; $i++) {
		$c .= '	<tr id="row_'.$i.'">
					<td width="30" valign="top">
						<img src="../lang/'.$l[$i]['directory'].'/'.$l[$i]['image'].'" alt="'.$l[$i]['name'].'" />
					</td>
					<td width="1" valign="top">
						<input type="text" value="" class="new_const" id="new_const_'.$i.'" />
					</td>
					<td>
						<textarea id="new_text_'.$i.'"></textarea>
					</td>
					<td width="1" align="right">
						<button class="button" onclick="saveNew('.$i.', '.$l[$i]['id'].');">
							Speichern
						</button>
					</td>
				</tr>';
	}
	$c .= '</table>';

	$ajax->assign('translation_results', 'innerHTML', $c);

	return $ajax;
}

$xajax->processRequest();
?>